<template>
  <div id="center">
    <div class="up">
      <div class="bg-color-black item" v-for="(item, index) in titleItem" :key="index" @click="jumpPage(index)"
        :style="index == 0 || index == 1 || index == 3 ? 'cursor: pointer' : ''">
        <p class="colorBlue titType" style="margin-left: 8px">{{ item.title }}</p>
        <div>
          <dv-digital-flop class="dv-dig-flop ml-1 mt-2 pl-3" :config="item.number" />
        </div>
      </div>
    </div>
    <div class="down">
      <div class="ranking bg-color-black">
        <span>
          <icon name="chart-pie" class="text-icon"></icon>
        </span>
        <span class="text mx-2 mb-1 pl-3" >商家活跃榜</span>
        <scrollRankingBoard class="dv-scr-rank-board mt-1" :config="ranking" @lineClick="lineClick" />
      </div>
      <div class="percent">
        <div class="item bg-color-black" @click="jumpWarning" style="cursor: pointer">
          <span>预警处理率</span>
          <CenterChart :id="rate[0].id" :tips="rate[0].tips" :colorObj="rate[0].colorData" />
        </div>
        <div class="item bg-color-black" @click="jumpAppeal" style="cursor: pointer">
          <span>申诉处理率</span>
          <CenterChart :id="rate[1].id" :tips="rate[1].tips" :colorObj="rate[1].colorData" />
        </div>
        <div class="water">
          <div class="item bg-color-black" @click="jumpWarning" style="cursor: pointer">
            <span>预警数量</span>
            <ring :id="rate[2].id" :tips="rate[2].tips" :colorObj="rate[2].colorData" />
          </div>
          <div class="item bg-color-black" @click="jumpAppeal" style="cursor: pointer">
            <span>消费者申诉</span>
            <ring :id="rate[3].id" :tips="rate[3].tips" :colorObj="rate[3].colorData" />
          </div>
          <!-- <div class="item bg-color-black">
            <span>预警数量</span>
            <div class="watre_one">20</div>
          </div>
          <div class="item bg-color-black">
            <span>预警数量</span>
            <div class="watre_one">20</div>
          </div> -->

          <!-- <dv-water-level-pond class="dv-wa-le-po" :config="water" /> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CenterChart from "@/components/echart/center/centerChartRate";
import ring from "@/components/echart/ring";
import scrollRankingBoard from "@/components/scrollRankingBoard";

import {
  platformStatistics,
  activeList,
  warning
} from "@/api/index";
import handleGetData from "@/mixins/handleGetData";
export default {
  mixins: [handleGetData],
  data() {
    return {
      areaId: '',
      titleItem: [{
        title: "累计上链商家（家）",
        number: {
          number: [0],
          toFixed: 0,
          textAlign: "left",
          content: "{nt}",
          style: {
            fontSize: 26,
          },
        },
      },
      {
        title: "今日上链商家（家）",
        number: {
          number: [0],
          toFixed: 1,
          textAlign: "left",
          content: "{nt}",
          style: {
            fontSize: 26,
          },
        },
      },
      {
        title: "累计使用平台（人）",
        number: {
          number: [0],
          toFixed: 1,
          textAlign: "left",
          content: "{nt}",
          style: {
            fontSize: 26,
          },
        },
      },
      {
        title: "累计售卡（张）",
        number: {
          number: [0],
          toFixed: 1,
          textAlign: "left",
          content: "{nt}",
          style: {
            fontSize: 26,
          },
        },
      },
      {
        title: "存管账户累计购卡金额（元）",
        number: {
          number: [0],
          toFixed: 1,
          textAlign: "left",
          content: "{nt}",
          style: {
            fontSize: 26,
          },
        },
      },
      {
        title: "存管账户剩余监管金额（元）",
        number: {
          number: [0],
          toFixed: 1,
          textAlign: "left",
          content: "{nt}",
          style: {
            fontSize: 26,
          },
        },
      },
      ],
      ranking: {
        data: [{
          name: "海口",
          value: 0,
        },],
        carousel: "single",
        sort: false,
        unit: "人",
      },
      water: {
        data: [24, 45],
        shape: "roundRect",
        formatter: "{value}%",
        waveNum: 3,
      },
      // 通过率和达标率的组件复用数据
      rate: [{
          id: "centerRate1",
          tips: 0,
          colorData: {
            textStyle: "#3fc0fb",
            series: {
              color: ["#00bcd44a", "transparent"],
              dataColor: {
                normal: "#03a9f4",
                shadowColor: "#97e2f5",
              },
            },
          },
        },
        {
          id: "centerRate2",
          tips: 0,
          colorData: {
            textStyle: "#67e0e3",
            series: {
              color: ["#faf3a378", "transparent"],
              dataColor: {
                normal: "#ff9800",
                shadowColor: "#fcebad",
              },
            },
          },
        },
        {
          id: "centerRate3",
          tips: 0,
          colorData: {
            textStyle: "#3fc0fb",
            series: {
              color: ["#00bcd44a", "transparent"],
              dataColor: {
                normal: "#03a9f4",
                shadowColor: "#97e2f5",
              },
            },
          },
        },
        {
          id: "centerRate4",
          tips: 0,
          colorData: {
            textStyle: "#67e0e3",
            series: {
              color: ["#faf3a378", "transparent"],
              dataColor: {
                normal: "#ff9800",
                shadowColor: "#fcebad",
              },
            },
          },
        },
      ],
    };
  },
  components: {
    CenterChart,
    ring,
    scrollRankingBoard,
  },
  created() {
    this.areaId = localStorage.getItem('areaId')
    // this.getplatformStatistics();
    // this.getActiveList();
    // this.getWarning();
    this._handleData();
    this.getData();
  },
  methods: {
    jumpPage(index) {
      // let api = 'http://192.168.0.118:9527'
      let api = process.env.VUE_APP_GOV_API
      if(api.includes('ins')){//政府端才用
        return
      }
      if (index == 0 || index == 1)
        window.location = api + '/merchants/MerchantsList';
      if (index == 3)
        window.location = api + '/blockChain/blockChain-list';

    },
    lineClick(item) {
      // let api = 'http://192.168.0.118:9527'
      let api = process.env.VUE_APP_GOV_API
      if (api.includes('ins')) {//政府端才用
        return
      }
      window.location = api + '/merchants/MerchantsList' + '?name=' + item.name;
    },
    jumpWarning() {
      // let api = 'http://192.168.0.118:9527'
      let api = process.env.VUE_APP_GOV_API
      if (api.includes('ins')) {//政府端才用
        return
      }
      window.location = api + '/warningComplaint/warning-list';
    },
    jumpAppeal() {
      // let api = 'http://192.168.0.118:9527';
      let api = process.env.VUE_APP_GOV_API
      if (api.includes('ins')) {//政府端才用
        return
      }
      window.location = api + '/warningComplaint/complaint-list';
    },
    getData() {
      this.getplatformStatistics();
      this.getActiveList();
      this.getWarning();
    },
    getplatformStatistics() {
      //查询平台统计信息（标记3）
      const params = {
        areaId: this.areaId
      };
      platformStatistics(params).then((res) => {
        let titleItem = [{
          title: "累计上链商家（家）",
          number: {
            number: [0],
            toFixed: 0,
            textAlign: "left",
            content: "{nt}",
            style: {
              fontSize: 26,
            },
          },
        },
        {
          title: "今日上链商家（家）",
          number: {
            number: [0],
            toFixed: 0,
            textAlign: "left",
            content: "{nt}",
            style: {
              fontSize: 26,
            },
          },
        },
        {
          title: "累计使用平台（人）",
          number: {
            number: [0],
            toFixed: 0,
            textAlign: "left",
            content: "{nt}",
            style: {
              fontSize: 26,
            },
          },
        },
        {
          title: "累计售卡（张）",
          number: {
            number: [0],
            toFixed: 0,
            textAlign: "left",
            content: "{nt}",
            style: {
              fontSize: 26,
            },
          },
        },
        {
          title: "存管账户累计购卡金额（元）",
          number: {
            number: [0],
            toFixed: 2,
            textAlign: "left",
            content: "{nt}",
            style: {
              fontSize: 26,
            },
          },
        },
        {
          title: "存管账户剩余监管金额（元）",
          number: {
            number: [0],
            toFixed: 2,
            textAlign: "left",
            content: "{nt}",
            style: {
              fontSize: 26,
            },
          },
        },
        ];
        titleItem[0].number.number[0] = res.result.merchantTotal;
        titleItem[1].number.number[0] = res.result.todayMerchantTotal;
        titleItem[2].number.number[0] = res.result.userTotal;
        titleItem[3].number.number[0] = res.result.cardTotal;
        titleItem[4].number.number[0] = res.result.sellCardMoneyTotal;
        titleItem[5].number.number[0] = res.result.freezeMoneyTotal;
        this.titleItem = titleItem;
      });
    },
    getActiveList() {
      //获取昨日商家活跃榜
      const params = {
        areaId: this.areaId
      };
      activeList(params).then((res) => {
        let ranking = {
          data: [],
          carousel: "single",
          unit: "人",
          sort: false,
        };
        ranking.data = res.result;
        this.ranking = ranking;
        console.log(this.ranking);
      });
    },
    getWarning() {
      //获取预警提醒
      const params = {
        areaId: this.areaId
      };
      warning(params).then((res) => {
        let rate = [{
          id: "centerRate1",
          tips: 0,
          colorData: {
            textStyle: "#3fc0fb",
            series: {
              color: ["#00bcd44a", "transparent"],
              dataColor: {
                normal: "#03a9f4",
                shadowColor: "#97e2f5",
              },
            },
          },
        },
        {
          id: "centerRate2",
          tips: 0,
          colorData: {
            textStyle: "#67e0e3",
            series: {
              color: ["#faf3a378", "transparent"],
              dataColor: {
                normal: "#ff9800",
                shadowColor: "#fcebad",
              },
            },
          },
        },
        {
          id: "centerRate3",
          tips: 0,
          colorData: {
            textStyle: "#3fc0fb",
            series: {
              color: ["#00bcd44a", "transparent"],
              dataColor: {
                normal: "#03a9f4",
                shadowColor: "#97e2f5",
              },
            },
          },
        },
        {
          id: "centerRate4",
          tips: 0,
          colorData: {
            textStyle: "#67e0e3",
            series: {
              color: ["#faf3a378", "transparent"],
              dataColor: {
                normal: "#ff9800",
                shadowColor: "#fcebad",
              },
            },
          },
        },
        ];
        rate[0].tips = Number(res.result.warnRatio);
        rate[1].tips = Number(res.result.appealRatio);
        rate[2].tips = Number(res.result.warnNum);
        rate[3].tips = Number(res.result.appealNum);
        this.rate = rate;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.titType {
  font-size: 12px;
  margin-left: 8px;
}

#center {
  display: flex;
  flex-direction: column;
  width: 700px;

  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;

    .item {
      border-radius: 6px;
      padding-top: 8px;
      margin-top: 4px;
      width: 32%;
      // cursor: pointer;
      height: 70px;

      .dv-dig-flop {
        width: 150px;
        height: 30px;
      }
    }
  }

  .down {
    padding: 6px 4px;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    height: 255px;
    justify-content: space-between;

    .bg-color-black {
      border-radius: 5px;
      // cursor: pointer;
    }

    .ranking {
      padding: 10px;
      width: 59%;

      .dv-scr-rank-board {
        height: 225px;
      }
    }

    .percent {
      width: 40%;
      display: flex;
      flex-wrap: wrap;

      .item {
        width: 50%;
        height: 120px;
        display: flex;
        flex-direction: column;
        align-items: center;

        span {
          margin-top: 8px;
          font-size: 14px;
          display: flex;
          justify-content: center;
        }
      }

      .water {
        width: 100%;
        display: flex;

        .dv-wa-le-po {
          height: 120px;
        }
      }
    }
  }

  .watre_one {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 1px solid #ccc;
  }
}
</style>